package MultiFomular;

import java.lang.reflect.Array;

import SingleLinkList.MyLinkList;

public class MultiFomular {
	private MyLinkList<Double> fomular;
	private double x;
	
	{
		fomular=new MyLinkList<>();
		x=0;
	}
	
	public MultiFomular(){};
	
	public MultiFomular(Double[] array){
		fomular=new MyLinkList<Double>((Double[])array);
	}
	
	MultiFomular(Double[] array , double x){
		fomular=new MyLinkList<Double>((Double[])array);
		setX(x);
	}
	
	public void setX(double x){
		this.x=x;
	}
	
	public double calcultor(){
		double result=fomular.get(0);
		int length=fomular.getSize();
		
		for (int i=1;i<length;++i){
			result+=fomular.get(i)*Math.pow(x, i);
		}
		
		return result;		
	}
	
	@Override
	public String toString(){
		StringBuilder str=new StringBuilder();
		
		int length=fomular.getSize();
		double num0=fomular.get(0);
		str.append(num0==0.0?"":num0);
		for (int i=1;i<length;++i){
			double num=fomular.get(i);
			str.append(((num<0?num:"+")+""+num+"*X^"+i));
		}
		return str.toString();
	}
	
}
